home *** CD-ROM | disk | FTP | other *** search
- Path: crchh327.rich.bnr.ca!jobell
- From: jobell@bnr.ca (Bret Bieghler)
- Newsgroups: comp.lang.c++
- Subject: Re: sizeof class
- Date: 27 Feb 1996 21:04:44 GMT
- Organization: Bell-Northern Research Ltd.
- Message-ID: <4gvrlc$2l6@crchh327.rich.bnr.ca>
- References: <Pine.SOL.3.91.960226185535.3663A-100000@turing.uncg.edu> <4gvi3s$53a@horn.wyoming.com>
- NNTP-Posting-Host: crchh524.rich.bnr.ca
-
- In article <4gvi3s$53a@horn.wyoming.com>,
- Dave Cromley <dcromley@wyoming.com> wrote:
- >Bin . Lee wrote:
- >>class TestClass {};
- >>sizeof TestClass is 1 for BC++, is this normal ?
- >>Where dose computer store this pointer ?
- >
- >Yes, it is 1, isn't it?
- >I would have thought the size would be 0.
- >There is no pointer.
- >
- >class TestClass2 { int i1; };
- >has a sizeof 2--the size of the int.
- >struct TestStruct { };
- >has a sizeof 1--I would have expected 0.
- >
- > Dave C.
- >
-
- C++ forces the size of objects to be of nozero
- size because each object must have a distinct
- address. (Bruce Eckel)
-
- Consider:
-
- TestClass aTestClassArray[100];
-
- if they are all of zero size, how do you index
- into the array?
-
- Therefore, the C++ compiler inserts a dummy.
-
- (See Bruce Eckel, "Thinking in C++", page 543).
-
- Joe
- --
- Joseph A. Bell (NOT Bret Bieghler) jobell@bnr.ca
- Northern Telecom / Bell-Northern Research
- "What? Evacuate now, in our moment of triumph? Surely you overestimate their chances."
-